<?php

    class PageController extends AdminController
    {   
        public function init(){
            parent::init();
            $this->menu_parent_selected = 'dashboard';
        }

        public function filters()
        {
            return array(
                'accessControl', // perform access control for CRUD operations
                'postOnly + delete', // we only allow deletion via POST request
            );
        }

        /**
        * Specifies the access control rules.
        * This method is used by the 'accessControl' filter.
        * @return array access control rules
        */
        public function accessRules()
        {
            return array(
                array('allow',
                    'actions'=>array('index', 'error', 'reIndex'),
                    'users'=>array('@'),
                ),
                array('deny',  // deny all users
                    'users'=>array('*'),
                ),
            );
        }    
        
        /**
        * This is the action to handle external exceptions.
        */
        public function actionError()
        {
            if($error=Yii::app()->errorHandler->error)
            {
                if(Yii::app()->request->isAjaxRequest)
                    echo $error['message'];
                else
                    $this->render('error', $error);
            }
        }

        public function actionIndex()
        {
            $this->menu_child_selected = 'default';
            $this->menu_sub_selected = 'index';

            $this->render('index');
        }
        
        public function actionReIndex(){
            Post::model()->reIndex();
            echo 'All posts were indexed!';
        }
        
}